var api = require("../../../../api.js"),
  app = getApp();
Page({
  data: {
    src:'',
    data:'',
    icons:''
  },

  pay:function(e){
    console.log('eee',e)
    var that = this
    var money = e.currentTarget.id
    // var member_grade = e.currentTarget.dataset.id
    var uid = wx.getStorageSync('uid');
    app.request({
      url: api.member.pay,
      data: {
        uid: uid,
        money: money,
      },
      method: 'get',
      success: function (e) {
        console.log('rerere', e)
        var pay = e.data.weixin;
        wx.requestPayment({
          timeStamp: pay.timeStamp,
          nonceStr: pay.nonceStr,
          package: pay.package,
          signType: pay.signType,
          paySign: pay.paySign,
          success: function (res) {
            wx.showToast({
              title: '购买成功',
              duration: 1000,
              success: function () {
                app.request({
                  url: api.member.study,
                  data: {
                    uid: uid,
                    // member_grade: member_grade,
                  },
                  method: 'get',
                  success: function (e) {
                    console.log("eeeee",e)
                  }
                })
              }
                // setTimeout(function () {
                //   wx.navigateBack({
                //     delta: 1
                //   })
                // }, 1000)
                // }
            })
          }
        })
        // var data = res.data.data
        // that.setData({
        //   data: data,
        // })
      }
    })
        
  },
  onLoad: function (options) {

  },
  onShow: function (options) {
    var that = this 
    that.setData({
      icons: wx.getStorageSync('site') + '/addons/sd_liferuning/tp/public/uploads/background',
    })
    var uid = wx.getStorageSync('uid');
    app.request({
      url: api.member.info,
      data:{
        uid: uid
      },
      method:'post',
      success:function(res){
        // console.log('resres',res)
        var member_grade = res.data.member_grade;
        if (res.data == 1001) {
          var src = ''
        } else if (member_grade == 1){
          var src = that.data.icons+'/resource/common/image/customer/member-center/level1_1.png'
        } else if (member_grade == 2){
          var src = that.data.icons +'/resource/common/image/customer/member-center/level2_1.png'
        } else if (member_grade == 3) {
          var src = that.data.icons +'/resource/common/image/customer/member-center/level3_1.png'
        } else if (member_grade == 4) {
          var src = that.data.icons +'/resource/common/image/customer/member-center/level4_1.png'
        } else if (member_grade == 5) {
          var src = that.data.icons +'/resource/common/image/customer/member-center/level5_1.png'
        }
        that.setData({
          src: src
        })
      }
    })
    app.request({
      url: api.member.memberin,
      data:{
        bid:wx.getStorageSync('bid')
      },
      method:'get',
      success:function(res){
        console.log('rerere', res.data)
        var data = res.data
        that.setData({
          data: data,
        })
      }
    })
  },
})